<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>methods</title>
  <script src="../assets/js/vue.min.js"></script>
</head>
<body>
  <h1>methods</h1>
  <hr>
  <div id="app">
    {{ number }}
    <button @click="add(2, $event)">add</button>
    <!-- 组件中的点击事件 -->
    <btn @click.native="aaa(4)"></btn>
  </div>
  <!-- 卸载外部的事件，不管是调用实例内的方法还是实例外部的方法，都需要在事件名后面加上'()'，否则不生效 -->
  <!-- <button onclick="clickOut()">外部</button> -->
  <button onclick="vue.bbb(33)">外部</button>
  <script>
    function clickOut() {
      vue.bbb();
    }
    var vue = new Vue({
      el: '#app',
      data: {
        number: 0
      },
      methods: {
        add: function (num, e) {
          if (num) {
            this.number += num;
          } else {
            this.number++;
          }
        },
        aaa: function (n) { 
          console.log(111, n);
        },
        bbb: function (n) { 
          console.log(222 + n);
        }
      },
      components: {
          btn: {
            template: `<button>btn组件</button>`
          }
        }
    })
  </script>
</body>
</html>